package com.jzg.jcptadmin.adpter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.app.AppContext;
import com.jzg.jcptadmin.data.vo.CarDetails;
import com.jzg.jcptadmin.view.CircularImageView;
import com.jzg.template.refreshrecycleview.RecycleViewBaseAdapter;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by jzg on 2015/12/28.
 */
public class PingguInfoAdapter extends RecycleViewBaseAdapter {

    private AppContext context;
    List<CarDetails.Reply> infos;
    public PingguInfoAdapter(AppContext context, List<CarDetails.Reply> infos) {
        this.context = context;
        this.infos = infos;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.task_view_item, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder1, int position) {
        super.onBindViewHolder(holder1, position);
        MyViewHolder holder = (MyViewHolder) holder1;
        holder.tvUsername.setText(infos.get(position).getNickName());
        holder.tvTime.setText(infos.get(position).getPassTime());
        holder.tvContent.setText(infos.get(position).getReplyContent());
        ImageLoader.getInstance().displayImage(infos.get(position).getHeadPic(), holder.ivUsernameimage, context.options);

    }

    @Override
    public int getItemCount() {
        return infos.size();
    }

    public void update(List<CarDetails.Reply> replyList) {
        this.infos = replyList;
        this.notifyDataSetChanged();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iv_usernameimage)
        CircularImageView ivUsernameimage;
        @Bind(R.id.tv_username)
        TextView tvUsername;
        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tv_content)
        TextView tvContent;

        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this,view);

        }
    }
}
